import traceback
from flask import Blueprint, request, make_response
from flask_restful import reqparse, inputs, Resource, Api, fields,marshal_with
from .res import output_json
from ..models.database import db,serialize
from ..models.console.admin import Admin
from ..models.console.menu import Menu
from ..decorator.consolejwt import console_token

from ..libs.tree import UpdateTable

# 蓝图并放入 restful
bp = Blueprint('auth', __name__, url_prefix='/auth')
api = Api(bp)

# 统一封装 API 返回值
@api.representation('application/json')
def out_json(data, code, headers=None):
    return output_json(data, code, headers=None)

# 请求验证
parser = reqparse.RequestParser()
# 封装放回的数据格式
resource_fields = {
    'name': fields.String,
    'address': fields.String,
    'user_id': fields.Integer
}
class HelloWorldResource(Resource):
    @console_token
    @marshal_with(resource_fields, envelope='resource')
    def get(self,todo_id):
        # parser.add_argument('todo_id', type=int,
        #                     help='管理员 ID 必须填写', location=['form', 'args'], required=True, action='store')
        # args = parser.parse_args()
        # t = UpdateTable();
        # t.update(Menu)
        return {'hello': 'world'}

    def post(self, todo_id):
        return {'msg': 'post hello world'}


api.add_resource(HelloWorldResource, '/restful/<todo_id>')
